home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-15 / phbench.zip / RUN-ALL.C < prev    next >
Text File  |  1993-01-04  |  3KB  |  111 lines

  1. /* do_allbench - run all the benchmark programs */
  2. #include <stdio.h>
  3. #define NBENCHES 6
  4. #define TIME_FMT "Current time is %lf:%lf:%lf"
  5. #define CPUTIME_MIN 10000.
  6. static struct timing
  7.        {
  8.        double cputime; char *fname; char *title1; char *title2;
  9.        } timings[NBENCHES] =
  10.        {
  11.        0., "benchreg", "register",     "int",
  12.        0., "benchsho", "auto",         "short",
  13.        0., "benchlng", "auto",         "long",
  14.        0., "benchmul", "integer",      "multiply",
  15.        0., "benchfn",  "function",     "call",
  16.        0., "benchdbl", "auto",         "double",
  17.        };
  18. static char cc_cmd[BUFSIZ] = {0};
  19. static char command[BUFSIZ] = {0};
  20. int compile(fname)
  21.        char *fname;
  22.        {
  23.        sprintf(command, cc_cmd, fname);
  24.        return (system(command));
  25.        }
  26. int mk_crlf()
  27.        {
  28.        FILE *crlf;
  29.  
  30.        crlf = fopen("cr-lf", "w");
  31.        if (crlf == NULL)
  32.                {
  33.                fprintf(stderr, "unable to create file  crlf\n");
  34.                exit(2);
  35.                }
  36.        putc('\n', crlf);
  37.        fclose(crlf);
  38.        }
  39. double rd_time(tmpname)
  40.        char *tmpname;
  41.        {
  42.        FILE *fp;
  43.        double hrs, mins, secs;
  44.  
  45.        fp = fopen(tmpname, "r");
  46.        fgets(buf, sizeof(buf), fp);
  47.        sscanf(buf, TIME_FMT, &hrs, &mins, &secs);
  48.        fclose(fp);
  49.        return (1000 * (secs + 60 * (mins + 60 * hrs));
  50.        }
  51. double time_it(fname, iterations)
  52.        char *fname;
  53.        long iterations;
  54.        {
  55.        double t0, t1;
  56.  
  57.        sprintf(command, "time <cr-lf >t0");
  58.        system(command);
  59.        t0 = rd_time("t0");
  60.        sprintf(command, "%s %ld", fname, iterations);
  61.        system(command);
  62.        sprintf(command, "time <cr-lf >t1");
  63.        system(command);
  64.        t1 = rd_time("t1");
  65.        return (t1 - t0);
  66.        }
  67. double run(fname, major)
  68.        char *fname;
  69.        long major;
  70.        {
  71.        double t_empty, t_major;
  72.  
  73.        t_empty = time_it(fname, 0L);
  74.        t_major = time_it(fname, major);
  75.        return (t_major - t_empty);
  76.        }
  77. double do_all(fname)
  78.        char *fname;
  79.        {
  80.        double cputime;
  81.        long major;
  82.  
  83.        compile(fname);
  84.        major = MAJOR_MIN;
  85.        do {
  86.                cputime = run(fname, major);
  87.                major *= 10;
  88.                } while (cputime < CPUTIME_MIN);
  89.        return (cputime / major);
  90.        }
  91. main(ac, av)
  92.        int ac;
  93.        char *av[];
  94.        {
  95.        int i;
  96.  
  97.        strcpy(cc_cmd, av[1]);
  98.        for (i = 0; i <= NBENCHES; ++i)
  99.                timings[i].cputime = do_all(timings[i].fname);
  100.        printf("\n\n\nRESULTS:\n\n");
  101.        for (i = 0; i <= NBENCHES; ++i)
  102.                printf("%10s  ", timings[i].title1;
  103.        printf(\n");
  104.        for (i = 0; i <= NBENCHES; ++i)
  105.                printf("%10s  ", timings[i].title2;
  106.        printf(\n");
  107.        for (i = 0; i <= NBENCHES; ++i)
  108.                printf("%10.4f  ", timings[i].cputime);
  109.        printf("\n\n(All times are in microseconds\n");
  110.        }
  111.